package com.yangj.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.dbutils.ResultSetHandler;
import com.yangj.model.AccompanyingPlay;
import com.yangj.model.AccompanyingPlayDetail;
import com.yangj.model.Game;
public class AccompanyingPlayDetailDao extends BaseDao {
	public AccompanyingPlayDetail get(int id) {
		try {
			String sql="select ap.id apid, ap.name apname, level_, order_count,"
					+ "    loc, acc_img, message, price,"
					+ "    dan,ge.id geid, ge.name gename, icon,"
					+ "    detail_id, top_img, state,"
					+ "    serve_count, order_receiving_time,"
					+ "    can_yield, can_dan, game_feature"
					+ "    from accompanying_play ap"
					+ "    join game ge on ap.game_id = ge.id and ap.id = ?"
					+ "    join accompanying_play_detail apd on apd.accompanying_play_id = ap.id";
			return queryRunner.query(sql, new ResultSetHandler<AccompanyingPlayDetail>() {
				@Override
				public AccompanyingPlayDetail handle(ResultSet rs) throws SQLException {
					if(rs.next()) {
//						String path = "http://127.0.0.1/";
						return new AccompanyingPlayDetail(
							    rs.getInt("detail_id"),
//							    path + rs.getString("top_img"),
							    rs.getString("top_img"),
							    rs.getInt("state"),
							    rs.getInt("serve_count"),
							    rs.getString("order_receiving_time"),
							    rs.getString("can_yield"),
							    rs.getString("can_dan"),
							    rs.getString("game_feature"),
							    new AccompanyingPlay(
							    		rs.getInt("apid"),
										rs.getString("apname"),
										rs.getDouble("level_"),
										rs.getInt("order_count"),
										rs.getString("loc"),
										rs.getString("acc_img"),
										rs.getString("message"),
										rs.getInt("price"),
										rs.getString("dan"),
										new Game(
												rs.getInt("geid"),
												rs.getString("gename")
												)
							    		)
							    );
					}
					return null;
				}
			},id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
